      SUBROUTINE OUTPT_OT(FI,DFI,RCONT,RCEX,RESID,I_ELET,
     &                  IDCASO,IC,NEPE,NCasos,FDEX,FROT)


      IMPLICIT DOUBLE PRECISION (A-H,O-Z)

      INCLUDE 'param_dim.inc'

      DIMENSION FI(NX),DFI(NX)
      DIMENSION RCONT(NRCX),RCEX(NRCX)
	  real*8 c

      INTEGER IDCASO(NCasosX,3),I_ELET(16,NELEX)
      INTEGER FDEX,FROT
      real resid
	double precision aux(16), aux1 

      IELET1= IDCASO(IC,1)
      IELET2= IDCASO(IC,2)
      IELET3= IDCASO(IC,3)

      IR0= (IC-1)*(16-3)
      IRES= 0


!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Para o padrao sheffield
!  Assume que as condicoes de contorno sao: J no E1 e E2, ref no E3, etc
!   Assume que E2 eh sempre maior que E1

	do IE=1,16
           INOF= I_ELET(IE,1+NEPE/2)
	   aux(IE) = FI(INOF)
	enddo
	
	
	
	do i=1,16
	    i1 = i
	    i2 = i+1
	
	    if (i2.gt.16) then
	      i2 = i2 - 16
	    endif
	    

! 	    if (ielet2-ielet1.ne.1 .or. ielet2-ielet1.ne.-15)then  !eletrodos de injecao vizinhos	    
	      if(i2 .eq. ielet2)then
		i2 = i2+1
		if (i2.gt.16) then
		  i2 = i2 - 16
		endif	      
	      endif 
! 	    endif

	    if (i1.ne.ielet1 .and. i1.ne.ielet2 .and. 
     &          i2.ne.ielet1 .and. i2.ne.ielet2)then 
		IRES= IRES + 1
		RCONT(IR0+IRES)= aux(i2)-aux(i1)
		write(*,*)ic, ires,i1,i2
	    endif


	enddo
	  

! 	aux1=aux(1)
! 	do I=1,15
! 		aux(i) = aux(i+1)-aux(i)
! 	enddo
! 	aux(16) = aux1 - aux(16)
! 
! 	if(ic .ne. 1 .and. ic .ne. 16)then
! 		DO I= 1,16
! 			IF( i .ne. (ic - 1) .and. 
!      &				i .ne. ic  .and.
!      &				i .ne. (ic + 1)) THEN
! 			IRES= IRES + 1
! 			RCONT(IR0+IRES)= aux(I)
! 			ENDIF
! 		ENDDO
! 	elseif(ic .eq. 1)then
! 		DO I= 1,16
! 			IF( i .ne. (16) .and. 
!      &				i .ne. (ic ) .and.
!      &				i .ne. (ic + 1)) THEN
! 			IRES= IRES + 1
! 			RCONT(IR0+IRES)= aux(I)
! 			ENDIF
! 		ENDDO
! 	elseif(ic .eq. 16)then
! 		DO I= 1,16
! 			IF( i .ne. (i-1) .and. 
!      &				i .ne. (ic ) .and.
!      &				i .ne. (1)) THEN
! 			IRES= IRES + 1
! 			RCONT(IR0+IRES)= aux(I)
! 			ENDIF
! 		ENDDO
! 	endif




      IF(IC.EQ.NCASOS) THEN

         NRC= NCASOS*(16-3)

         RESID= 0.D0
         DO I=1,NRC
            RESID= RESID + (RCONT(I)-RCEX(I))*(RCONT(I)-RCEX(I))
         ENDDO
         RESID= 0.5 * RESID

         WRITE(FROT,1010) (RCEX(I),I=1,NRC)

         WRITE(FROT,1010) ((RCONT(I)),I=1,NRC)
 1010    FORMAT(8(13E12.4,/))

         WRITE(FROT,1020) RESID
 1020    FORMAT(5X,'RESIDUO :',E15.5)
      
      ENDIF


     
      RETURN
      END


